//
//  SureOrderVc.m
//  WY_Milk
//
//  Created by wangyang on 2020/2/3.
//  Copyright © 2020 wangyang. All rights reserved.
//

#import "SureOrderVc.h"

@interface SureOrderVc ()
@property (nonatomic,strong) UIScrollView   *WyScrollView;

@end

@implementation SureOrderVc

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"提交预定";
    self.view.backgroundColor = UIColorFromRGB(0xFAFAFA);
    
    [self WyScrollView];
    
    if (@available(iOS 11.0, *)) {
               
               self.WyScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
           }
    
    
    [self initSetUI];
}


-(void)initSetUI{
    
    NSArray *LeftArray = @[@"收货人",@"联系方式",@"购买数量",@"收货地址",@"送达时间"];
    NSArray *RightArray = @[@"请输入联系人姓名",@"请输入联系电话",@"请输入购买数量",@"请输入收货地址",@"请输入送达时间"];
    for (int i = 0; i<LeftArray.count; i++) {
        
        UILabel *leftLabe = [UILabel labelWithContent:LeftArray[i] superView:self.OneView textColor:WyBlackColor font:WySYSTEMFONT(17) textAlignment:NSTextAlignmentLeft];
        [leftLabe mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(52)));
            make.top.equalTo(self.InformationLabe.bottom).offset(BiLiWidth(0)+BiLiWidth(52)*i);
            make.left.mas_offset(BiLiWidth(16));
        }];
        
        
        UITextField * WyTextField = [[UITextField alloc]init];
        [_OneView addSubview:WyTextField];
        WyTextField.placeholder = RightArray[i];
        WyTextField.textAlignment = NSTextAlignmentRight;
        WyTextField.font = WySYSTEMFONT(17);
        WyTextField.textColor = UIColorFromRGB(0x888888);
        [WyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(260), BiLiWidth(20)));
            make.right.mas_offset(BiLiWidth(-15));
            make.top.equalTo(self.InformationLabe.bottom).offset(BiLiWidth(0)+BiLiWidth(52)*i);
        }];
        WyTextField.tag = i;
        if (WyTextField.tag == 0) {
            _NameTextField = WyTextField;
        }
        else if (WyTextField.tag == 1)
        {
            _PhoneTextField = WyTextField;
        }
        else if (WyTextField.tag == 2)
        {
            _NumberTextField = WyTextField;
        }
        else if (WyTextField.tag == 3)
        {
            _AddTextField = WyTextField;
        }
        else if (WyTextField.tag == 4)
        {
            _TimeTextField = WyTextField;
        }
    }
    
    
    
    NSArray *fuleiArray = @[_SureOrderVcDicy[@"name"],_SureOrderVcDicy[@"UserName"],_SureOrderVcDicy[@"Score"],_SureOrderVcDicy[@"money"]];
           for (int i = 0; i<fuleiArray.count; i++) {
               UILabel *labe = [UILabel labelWithContent:fuleiArray[i]superView:self.TwoView textColor:WyBlackColor font:WySYSTEMFONT(14) textAlignment:NSTextAlignmentLeft];
               [labe mas_makeConstraints:^(MASConstraintMaker *make) {
                   make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(20)));
                   make.left.equalTo(self.PicImg.right).offset(BiLiWidth(10));
                   make.top.mas_offset(BiLiWidth(10)+BiLiWidth(25)*i);
               }];
               labe.tag = i;
               if (labe.tag == 0) {
                   _NameLabe = labe;
               }else if (labe.tag == 1)
               {
                   _UserNameLabe = labe;
                   _UserNameLabe.textColor = UIColorFromRGB(0x999999);
                   
               }
               else if (labe.tag == 2)
               {
                   _ScoreLabe = labe;
                   _ScoreLabe.textColor = UIColorFromRGB(0xFADB14);
           
               }
               else if (labe.tag == 3)
               {
                   _MoneyLabe = labe;
                   _MoneyLabe.textColor = UIColorFromRGB(0xFF4949);
                   
               }
           }
    
    
    
}


-(void)selector
{
    
    
    [MyProgressHUD showWithMaskType:MyProgressHUDMaskTypeBlack];
    
    

    //定时器
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
       
      [MyProgressHUD dismiss];
     
        
        
        if (self->_NameTextField.text.length == 0) {
            
            [[AlertControllerCustom shareInstance] showAlert:@"请输入联系人姓名" viewController:self];
        }
        
        if (self->_PhoneTextField.text.length == 0) {
            
            [[AlertControllerCustom shareInstance] showAlert:@"请输入联系电话" viewController:self];
        }
        
        if (self->_NumberTextField.text.length == 0) {
               
            [[AlertControllerCustom shareInstance] showAlert:@"请输入购买数量" viewController:self];
        }
        
        if (self->_AddTextField.text.length == 0) {
               
            [[AlertControllerCustom shareInstance] showAlert:@"请输入收货地址" viewController:self];
        }
        
        if (self->_TimeTextField.text.length == 0) {
               
            [[AlertControllerCustom shareInstance] showAlert:@"请输入送达时间" viewController:self];
        }
        
       
        
        if (self->_NameTextField.text.length >0 && self->_PhoneTextField.text.length >0 && self->_NumberTextField.text.length >0 && self->_AddTextField.text.length >0 && self->_TimeTextField.text.length >0) {
            [[AlertControllerCustom shareInstance] showAlert:@"预约成功" viewController:self];
             dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                 [self.navigationController popViewControllerAnimated:YES];
                  });
            
        }
        else
        {
            [[AlertControllerCustom shareInstance] showAlert:@"预约失败" viewController:self];
        }
        
        
        
        
    });

    
    
    
    
}


- (UIScrollView *)WyScrollView {
    
    if (!_WyScrollView) {
        _WyScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
        [self.view addSubview:_WyScrollView];
        _WyScrollView.userInteractionEnabled = YES;
        _WyScrollView.showsVerticalScrollIndicator = NO;
        _WyScrollView.contentSize = CGSizeMake(WySCREENWIDTH, WySCREENHEIGHT*1.3);
        [_WyScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        [self TwoView];
        [self OneView];
        
        [self WyBtn];
    }
    return _WyScrollView;
}
-(UIView *)TwoView

{
    
    if (!_TwoView) {
        _TwoView = [[UIView alloc]init];
        [self.WyScrollView addSubview:_TwoView];
        _TwoView.backgroundColor = [UIColor whiteColor];
        [_TwoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH, BiLiWidth(110)));
            make.top.mas_offset(BiLiWidth(10));
            make.centerX.mas_offset(0);
        }];
       
        
    }
    return _TwoView;
    
}
-(UIView *)OneView

{
    
    if (!_OneView) {
        _OneView = [[UIView alloc]init];
        [self.WyScrollView addSubview:_OneView];
        _OneView.backgroundColor = [UIColor whiteColor];
        _OneView.userInteractionEnabled = YES;
        [_OneView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH, BiLiWidth(312)));
            make.top.equalTo(self.TwoView.bottom).offset(BiLiWidth(20));
            make.centerX.mas_offset(0);
        }];
        [self InformationLabe];
    }
    return _OneView;
    
}

- (UILabel *)InformationLabe

{
    if (!_InformationLabe) {
        
        _InformationLabe = [UILabel labelWithContent:@"填写信息" superView:self.OneView textColor:WyBlackColor font:WySYSTEMFONT(17) textAlignment:NSTextAlignmentLeft];
        [_InformationLabe mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(200), BiLiWidth(52)));
            make.left.mas_offset(BiLiWidth(16));
            make.top.mas_offset(0);
        }];
    }
    return _InformationLabe;
}


- (UIImageView *)PicImg

{
    if (!_PicImg) {
        _PicImg = [UIImageView imageWithImgName:_SureOrderVcDicy[@"img"] superView:self.TwoView];
        _PicImg.backgroundColor = WyColor;
        WyViewRadius(_PicImg, BiLiWidth(5));
        [_PicImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(BiLiWidth(65), BiLiWidth(95)));
            make.top.mas_offset(BiLiWidth(10));
            make.left.mas_offset(BiLiWidth(20));
        }];
    }
    return _PicImg;
}



- (UIButton *)WyBtn

{
    if (!_WyBtn) {
        
        _WyBtn = [UIButton ButtonWithText:@"立即预定" superView:self.WyScrollView TextNormalcolor:WyWhiteColor backgroundColor:UIColorFromRGB(0xFADB14) fontSize:16 addTarget:self selector:@selector(selector)];
        WyViewRadius(_WyBtn, BiLiWidth(4));
        [_WyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.equalTo(CGSizeMake(WySCREENWIDTH-BiLiWidth(30), BiLiWidth(50)));
            make.top.equalTo(self.OneView.bottom).offset(BiLiWidth(40));
            make.centerX.mas_offset(BiLiWidth(0));
        }];
    }
    return _WyBtn;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
